﻿#include <QJsonObject>
#include <QJsonParseError>
#include <QDebug>
#include "modbusrtu.h"
#include "widgetserialportcfg.h"

ModbusRtu::ModbusRtu(QObject *parent):BaseModbus(parent)
{

}

ModbusRtu::~ModbusRtu()
{
    BaseModbus::~BaseModbus();
}

void ModbusRtu::setConfig(QJsonObject obj)
{
    BaseModbus::setConfig(obj);
    QString portName=obj["address"].toString();
    int baudRate=obj["baud_rate"].toInt();
    m_ctx=modbus_new_rtu(portName.toStdString().c_str(),baudRate,'N',8,1);
}

QWidget *ModbusRtu::getConfigWidget()
{
    WidgetSerialPortCfg *cfg=new WidgetSerialPortCfg();
    cfg->setComm(this);
    return cfg;
}
